package com.multitrack.googlemap;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.location.Location;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

public class GMapLocationDrawRadius extends MyLocationOverlay{

	/** Called when the activity is first created. */

	private Paint paint;
	private static final int DISTANCE_GAP = 10;
	private static final int CIRCLE_MIN_SIZE = 50;

	public GMapLocationDrawRadius(Context context, MapView mapView) {
		super(context, mapView);
		// TODO Auto-generated constructor stub
		paint = new Paint();
		setPaint();
	}

	@Override
	protected void drawMyLocation(Canvas canvas, MapView mapView,
			Location lastFix, GeoPoint myLocation, long when) {
		// TODO Auto-generated method stub
		super.drawMyLocation(canvas, mapView, lastFix, myLocation, when);
		Point point = mapView.getProjection().toPixels(myLocation, null);

		float radius = (float) Math.pow(2, mapView.getZoomLevel()
				- DISTANCE_GAP);

		if (radius < canvas.getHeight() / CIRCLE_MIN_SIZE) {
			radius = canvas.getHeight() / CIRCLE_MIN_SIZE;
		}

		canvas.drawCircle(point.x, point.y, radius, paint);
	}
	
	public void setPaint() {
		
		paint.setARGB(128, 0, 0, 255);
		paint.setStrokeWidth(2);
		paint.setStrokeCap(Paint.Cap.ROUND);
		paint.setAntiAlias(true);
		paint.setDither(false);
		paint.setStyle(Paint.Style.STROKE);
	}


}
